package daydayup;

import java.util.Arrays;

public class Q1984 {

    public int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int result = Integer.MAX_VALUE;
        for (int i = 0, j = k - 1; j < nums.length; i++, j++) {
            if (nums[j] - nums[i] < result) {
                result = nums[j] - nums[i];
            }
        }
        return result;
    }
}
